import server from '../../configure/server/index.js'
import { TOKEN, USER_INFO } from "./../../constant/index.js"
import { showLoading,showMsg } from "./../msg.js"
import { errorHandle } from './errHandle.js';

export function httpReq(config){
	let { url,method,data } = config;
	data = data || {};
	
	return new Promise((resolve,reject)=>{
		// if(loading != 'none'){
		// 	showLoading();
		// }
		uni.request({
			url: server.baseUrl + url, 
			method: method,
			header: {
				'token': uni.getStorageSync(TOKEN)
			},
			data,
			success: (res) => {
				let data = res.data;

				if (data.code == 200) {
					resolve(data.data);
				}else{
					errorHandle(res)
					reject(res)
				}
				
			},
			fail:function(err){
				// uni.hideLoading();
				errorHandle(err)
				console.log(err)
			
			}
		});
		
	})
	
}

